﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Account/Site.master" AutoEventWireup="true" CodeFile="SanPham.aspx.cs" Inherits="Administrator_SanPham" %>

<%@ Register assembly="FredCK.FCKeditorV2" namespace="FredCK.FCKeditorV2" tagprefix="FCKeditorV2" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
    </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <asp:SiteMapPath ID="SiteMapPath1" runat="server" Font-Names="Verdana" 
        Font-Size="0.8em" PathSeparator=" : " style="font-size: small">
        <CurrentNodeStyle ForeColor="#333333" />
        <NodeStyle Font-Bold="True" ForeColor="#284E98" />
        <PathSeparatorStyle Font-Bold="True" ForeColor="#507CD1" />
        <RootNodeStyle Font-Bold="True" ForeColor="#507CD1" />
    </asp:SiteMapPath>
    <br />
    <asp:Label ID="Label1" runat="server" 
        style="font-size: x-large; font-weight: 700" Text="Quản lý sản phẩm"></asp:Label>
    <br />
    <table class="style1">
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
        <tr>
            <td colspan="8">
                <asp:SqlDataSource ID="ThuongHieu1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:ConnectServer %>" SelectCommand="SELECT [ID], [Ten] FROM [NhanHieu] WHERE ([Xoa] = @Xoa)
and ID in(select NhanHieuID from sanpham where xoa=0 group by NhanHieuID)">
                    <SelectParameters>
                        <asp:Parameter DefaultValue="false" Name="Xoa" Type="Boolean" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="Loai1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:ConnectServer %>" 
                    
                    SelectCommand="SELECT ID, TenLoai FROM Loai WHERE (Xoa = 0) AND (ID IN (SELECT LoaiID FROM SanPham WHERE (Xoa = 0) AND (NhanHieuID = @nhanhieu) group by LoaiID))">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="ddthuonghieu1" Name="nhanhieu" 
                            PropertyName="SelectedValue" />
                    </SelectParameters>
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="ChucNang1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:ConnectServer %>" 
                    
                    SelectCommand="SELECT ID, Ten FROM ChucNang WHERE (Xoa = 0) AND (ID IN (SELECT ChucNangID FROM SanPham WHERE (Xoa = 0) AND (LoaiID = @Loai) and NhanHieuID=@nhanhieu group by chucnangID))">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="ddLoai1" Name="Loai" 
                            PropertyName="SelectedValue" />
                        <asp:ControlParameter ControlID="ddthuonghieu1" Name="nhanhieu" 
                            PropertyName="SelectedValue" />
                    </SelectParameters>
                </asp:SqlDataSource>
    <asp:LinkButton ID="LinkButton2" runat="server" 
        PostBackUrl="~/Administrator/ctSanPham.aspx">Thêm mới sản phẩm</asp:LinkButton>
            </td>
        </tr>
        <tr>
            <td width="150px">
                Lọc sản phẩm</td>
            <td align="right" width="100px">
                Thương hiệu</td>
            <td width="100px">
                <asp:DropDownList ID="ddthuonghieu1" runat="server" AutoPostBack="True" 
                    DataSourceID="ThuongHieu1" DataTextField="Ten" DataValueField="ID" 
                    Width="100px" AppendDataBoundItems="True" 
                    onselectedindexchanged="ddthuonghieu1_SelectedIndexChanged">
                    <asp:ListItem Value="-1">All</asp:ListItem>
                </asp:DropDownList>
            </td>
            <td align="right" width="150px">
                Loại sản phẩm</td>
            <td width="100px">
                <asp:DropDownList ID="ddLoai1" runat="server" AutoPostBack="True" 
                    DataSourceID="Loai1" DataTextField="TenLoai" DataValueField="ID" 
                    Width="100px" AppendDataBoundItems="True" 
                    onselectedindexchanged="ddLoai1_SelectedIndexChanged" Enabled="False">
                    <asp:ListItem Value="-1">All</asp:ListItem>
                </asp:DropDownList>
            </td>
            <td align="right" width="150px">
                Chức năng</td>
            <td width="100px">
                <asp:DropDownList ID="ddchucnang1" runat="server" AutoPostBack="True" 
                    DataSourceID="ChucNang1" DataTextField="Ten" DataValueField="ID" 
                    Width="100px" AppendDataBoundItems="True" 
                    onselectedindexchanged="ddchucnang1_SelectedIndexChanged" Enabled="False">
                    <asp:ListItem Value="-1">All</asp:ListItem>
                </asp:DropDownList>
            </td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        AllowSorting="True" AutoGenerateColumns="False" BackColor="White" 
        BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" 
        DataKeyNames="MaSanPham" 
        EnableModelValidation="True" Width="100%" DataSourceID="NhanHieu2" 
        onpageindexchanging="GridView1_PageIndexChanging" PageSize="30">
        <Columns>
            <asp:HyperLinkField DataNavigateUrlFields="MaSanPham" 
                DataNavigateUrlFormatString="ctSanPham.aspx?ID={0}" DataTextField="MaSanPham" 
                HeaderText="Mã sản phẩm" />
            <asp:BoundField DataField="GiaBan" HeaderText="Giá bán" />
            <asp:BoundField DataField="NgayCapNhat" HeaderText="Ngày cập nhật" />
            <asp:HyperLinkField DataNavigateUrlFields="MaSanPham" 
                DataNavigateUrlFormatString="HinhAnh.aspx?ID={0}" Text="Cập nhật hình ảnh" />
            <asp:BoundField DataField="tenchucnang" HeaderText="Chức năng" />
            <asp:BoundField DataField="tenloai" HeaderText="Loại sản phẩm" />
            <asp:BoundField DataField="tennhanhieu" HeaderText="Nhãn hiệu" />
        </Columns>
        <EmptyDataTemplate>
            Không có sản phẩn nào (Click Thêm sản phẩm mới)
        </EmptyDataTemplate>
        <FooterStyle BackColor="White" ForeColor="#000066" />
        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
        <RowStyle ForeColor="#000066" />
        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectServer %>" 
        DeleteCommand="UPDATE [SanPham] SET [Xoa] = 1 WHERE [MaSanPham] = @MaSanPham" 
        InsertCommand="INSERT INTO [SanPham] ([MaSanPham], [GiaBan], [NgayCapNhat], [LoaiID], [Xoa], [GioiThieu], [ChucNangID], [NhanHieuID]) VALUES (@MaSanPham, @GiaBan, @NgayCapNhat, @LoaiID, @Xoa, @GioiThieu, @ChucNangID, @NhanHieuID)" 
        SelectCommand="SELECT SanPham.MaSanPham, SanPham.GiaBan, SanPham.NgayCapNhat, SanPham.LoaiID, SanPham.Xoa, SanPham.GioiThieu, SanPham.ChucNangID, SanPham.NhanHieuID, Loai.TenLoai AS tenloai, ChucNang.Ten AS tenchucnang, NhanHieu.Ten AS tennhanhieu FROM SanPham INNER JOIN Loai ON SanPham.LoaiID = Loai.ID INNER JOIN NhanHieu ON SanPham.NhanHieuID = NhanHieu.ID LEFT OUTER JOIN ChucNang ON SanPham.ChucNangID = ChucNang.ID WHERE (SanPham.LoaiID = @loai1) AND (SanPham.NhanHieuID = @nhanhieu1) AND (SanPham.ChucNangID = @chucnang1) AND (SanPham.Xoa = @Xoa) AND (SanPham.LoaiID IN (SELECT ID FROM Loai AS Loai_1 WHERE (Xoa = 0))) AND (SanPham.ChucNangID IN (SELECT ID FROM ChucNang AS ChucNang_1 WHERE (Xoa = 0)) OR SanPham.ChucNangID IS NULL) AND (SanPham.NhanHieuID IN (SELECT ID FROM NhanHieu AS NhanHieu_1 WHERE (SanPham.Xoa = 0))) ORDER BY SanPham.NgayCapNhat DESC" 
        
        
        
        
        
        
        UpdateCommand="UPDATE [SanPham] SET [GiaBan] = @GiaBan, [NgayCapNhat] = @NgayCapNhat, [LoaiID] = @LoaiID, [Xoa] = @Xoa, [GioiThieu] = @GioiThieu, [ChucNangID] = @ChucNangID, [NhanHieuID] = @NhanHieuID WHERE [MaSanPham] = @MaSanPham">
        <DeleteParameters>
            <asp:Parameter Name="MaSanPham" Type="String" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="MaSanPham" Type="String" />
            <asp:Parameter Name="GiaBan" Type="Double" />
            <asp:Parameter Name="NgayCapNhat" Type="DateTime" />
            <asp:Parameter Name="LoaiID" Type="Int32" />
            <asp:Parameter Name="Xoa" Type="Boolean" />
            <asp:Parameter Name="GioiThieu" Type="String" />
            <asp:Parameter Name="ChucNangID" Type="Int32" />
            <asp:Parameter Name="NhanHieuID" Type="Int32" />
        </InsertParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="ddLoai1" Name="loai1" 
                PropertyName="SelectedValue" />
            <asp:ControlParameter ControlID="ddthuonghieu1" Name="nhanhieu1" 
                PropertyName="SelectedValue" />
            <asp:ControlParameter ControlID="ddchucnang1" Name="chucnang1" 
                PropertyName="SelectedValue" />
            <asp:Parameter DefaultValue="false" Name="Xoa" Type="Boolean" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="GiaBan" Type="Double" />
            <asp:Parameter Name="NgayCapNhat" Type="DateTime" />
            <asp:Parameter Name="LoaiID" Type="Int32" />
            <asp:Parameter Name="Xoa" Type="Boolean" />
            <asp:Parameter Name="GioiThieu" Type="String" />
            <asp:Parameter Name="ChucNangID" Type="Int32" />
            <asp:Parameter Name="NhanHieuID" Type="Int32" />
            <asp:Parameter Name="MaSanPham" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="NhanHieu2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectServer %>" 
        
        
        
        
        SelectCommand="SELECT SanPham.MaSanPham, SanPham.GiaBan, SanPham.NgayCapNhat, SanPham.LoaiID, SanPham.Xoa, SanPham.GioiThieu, SanPham.ChucNangID, SanPham.NhanHieuID, Loai.TenLoai AS tenloai, NhanHieu.Ten AS tennhanhieu, ChucNang.Ten AS tenchucnang FROM SanPham INNER JOIN Loai ON SanPham.LoaiID = Loai.ID INNER JOIN NhanHieu ON SanPham.NhanHieuID = NhanHieu.ID LEFT OUTER JOIN ChucNang ON SanPham.ChucNangID = ChucNang.ID WHERE (SanPham.Xoa = @Xoa) AND (SanPham.LoaiID IN (SELECT ID FROM Loai AS Loai_1 WHERE (Xoa = 0))) AND (SanPham.ChucNangID IN (SELECT ID FROM ChucNang AS ChucNang_1 WHERE (Xoa = 0)) OR SanPham.ChucNangID IS NULL) AND (SanPham.NhanHieuID IN (SELECT ID FROM NhanHieu AS NhanHieu_1 WHERE (SanPham.Xoa = 0))) ORDER BY SanPham.NgayCapNhat DESC">
        <SelectParameters>
            <asp:Parameter DefaultValue="false" Name="Xoa" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="Loai2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectServer %>" 
        
        
        
        SelectCommand="SELECT SanPham.MaSanPham, SanPham.GiaBan, SanPham.NgayCapNhat, SanPham.LoaiID, SanPham.Xoa, SanPham.GioiThieu, SanPham.ChucNangID, SanPham.NhanHieuID, Loai.TenLoai AS tenloai, ChucNang.Ten AS tenchucnang, NhanHieu.Ten AS tennhanhieu FROM SanPham INNER JOIN NhanHieu ON SanPham.NhanHieuID = NhanHieu.ID INNER JOIN Loai ON SanPham.LoaiID = Loai.ID LEFT OUTER JOIN ChucNang ON SanPham.ChucNangID = ChucNang.ID WHERE (SanPham.NhanHieuID = @nhanhieu1) AND (SanPham.Xoa = @Xoa) AND (SanPham.LoaiID IN (SELECT ID FROM Loai AS Loai_1 WHERE (Xoa = 0))) AND (SanPham.ChucNangID IN (SELECT ID FROM ChucNang AS ChucNang_1 WHERE (Xoa = 0)) OR SanPham.ChucNangID IS NULL) AND (SanPham.NhanHieuID IN (SELECT ID FROM NhanHieu AS NhanHieu_1 WHERE (SanPham.Xoa = 0))) ORDER BY SanPham.NgayCapNhat DESC">
        <SelectParameters>
            <asp:ControlParameter ControlID="ddthuonghieu1" Name="nhanhieu1" 
                PropertyName="SelectedValue" />
            <asp:Parameter DefaultValue="false" Name="Xoa" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="ChucNang2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ConnectServer %>" 
        
        
        
        SelectCommand="SELECT SanPham.MaSanPham, SanPham.GiaBan, SanPham.NgayCapNhat, SanPham.LoaiID, SanPham.Xoa, SanPham.GioiThieu, SanPham.ChucNangID, SanPham.NhanHieuID, ChucNang.Ten AS tenchucnang, Loai.TenLoai AS tenloai, NhanHieu.Ten AS tennhanhieu FROM SanPham INNER JOIN Loai ON SanPham.LoaiID = Loai.ID INNER JOIN NhanHieu ON SanPham.NhanHieuID = NhanHieu.ID LEFT OUTER JOIN ChucNang ON SanPham.ChucNangID = ChucNang.ID WHERE (SanPham.LoaiID = @loai1) AND (SanPham.NhanHieuID = @nhanhieu1) AND (SanPham.Xoa = @Xoa) AND (SanPham.LoaiID IN (SELECT ID FROM Loai AS Loai_1 WHERE (Xoa = 0))) AND (SanPham.ChucNangID IN (SELECT ID FROM ChucNang AS ChucNang_1 WHERE (Xoa = 0)) OR SanPham.ChucNangID IS NULL) AND (SanPham.NhanHieuID IN (SELECT ID FROM NhanHieu AS NhanHieu_1 WHERE (SanPham.Xoa = 0))) ORDER BY SanPham.NgayCapNhat DESC">
        <SelectParameters>
            <asp:ControlParameter ControlID="ddLoai1" Name="loai1" 
                PropertyName="SelectedValue" />
            <asp:ControlParameter ControlID="ddthuonghieu1" Name="nhanhieu1" 
                PropertyName="SelectedValue" />
            <asp:Parameter DefaultValue="false" Name="Xoa" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:LinkButton ID="LinkButton1" runat="server" 
        PostBackUrl="~/Administrator/ctSanPham.aspx">Thêm mới sản phẩm</asp:LinkButton>
    <br />
</asp:Content>

